/**
 * Created by JetBrains WebStorm.
 * User: Tonis
 * Date: 14.03.12
 * Time: 14:33
 * To change this template use File | Settings | File Templates.
 */
function Button(initValues) {
    if (initValues){this.setInitValues(initValues);}

}

Button.method('setInitValues', function(initValues){
    console.log("siin: ");
    this.x = initValues.x || 0;
    this.y = initValues.y || 0;
    this.w = initValues.w || 1;
    this.h = initValues.h || 1;
    this.fill = initValues.fill || '#AAAAAA';
    this.text = initValues.text || "Default";
    this.border = false;
    return this;
});

Button.method('draw',function () {
    OurGame.ctx.fillStyle = this.fill;
    OurGame.ctx.fillRect(this.x, this.y, this.w, this.h);
    OurGame.ctx.fillStyle = "#000000";
    OurGame.ctx.font="30px Arial";
    OurGame.ctx.fillText(this.text, this.x + 10, this.y + (this.h /2) + 10);
    if (this.border){
        OurGame.ctx.strokeStyle = "#FF0000";
        OurGame.ctx.strokeRect(this.x-1, this.y-1, this.w+1, this.h+1);

    }
});

Button.method('setBorder', function(border){
    this.border = border;
});

Button.method('isWithinBounds',function (mx, my) {
    return  (this.x <= mx) && (this.x + this.w >= mx) &&
        (this.y <= my) && (this.y + this.h >= my);
});

Button.method('onClick',function () {
    alert("onClick should be overridden in sub class of Button!");
});

function GameMode(initValues){
    console.log("test: " + initValues.text);
    this.setInitValues(initValues);
    this.type = initValues.type || GameModeSelection.PLAYERvsPLAYER;
}

GameMode.inherits(Button);

GameMode.method('onClick',function () {
    switch (this.type){
        case GameModeSelection.PLAYERvsPLAYER:
            initTwoPlayerGame();
            break;
        case GameModeSelection.PLAYERvsAI:
            initOnePlayerGame();
            break;
        case GameModeSelection.MultiPLAYER:
            initTwoPlayerGame();
            break;
    }
    OurGame.buttons = null;
    OurGame.gameModeSelected = true;
    OurGame.canvas.removeEventListener('mousedown', mouseDownOnButtons, false);
    OurGame.canvas.removeEventListener('mousemove', mouseMoveOnButtons, false);
});

function StartNewGame(initValues){
   this.setInitValues(initValues);
}

StartNewGame.inherits(Button);

StartNewGame.method('onClick',function () {
    location.reload();
} );
